package cn.bearspark.article.provider.dao.key;

import cn.bearspark.framework.redis.starter.buffer.hash.un.RedisHashBufferKeyBuilder;
import cn.bearspark.framework.redis.starter.key.RedisKeyBuilder;
import org.springframework.stereotype.Component;

/**
 * 专栏数据的缓存器的键的构造器
 *
 * @author f
 */
@Component
public class ArticleBufferKeyBuilder extends RedisKeyBuilder implements RedisHashBufferKeyBuilder {

    /**
     * 专栏信息的缓存的键的前缀
     */
    private static final String ARTICLE_INFO = "articleInfo";

    /**
     * 专栏分类 id 集合的缓存的键的前缀
     */
    private static final String ARTICLE_CATEGORY_ID_LIST = "articleCategoryIdList";

    /**
     * 用户专栏 id 集合的缓存的键的前缀
     */
    private static final String USER_ARTICLE_ID_LIST = "userArticleIdList";

    @Override
    public String buildHashBufferKey(long articleId) {
        return super.getPrefix() + ARTICLE_INFO + super.getSplitItem() + articleId;
    }

    public String buildCategoryIdListKey(long articleId) {
        return super.getPrefix() + ARTICLE_CATEGORY_ID_LIST + super.getSplitItem() + articleId;
    }

    public String buildUserArticleIdListKeyPattern(long userId) {
        return super.getPrefix() + USER_ARTICLE_ID_LIST + super.getSplitItem() + userId + "*";
    }

    public String buildUserArticleIdListKey(long userId, int visCode) {
        return super.getPrefix() + USER_ARTICLE_ID_LIST +
               super.getSplitItem() + userId +
               super.getSplitItem() + "all" +
               super.getSplitItem() + visCode;
    }

    public String buildUserCategoryArticleIdListKey(long userId, long categoryId, int visCode) {
        return super.getPrefix() + USER_ARTICLE_ID_LIST +
               super.getSplitItem() + userId +
               super.getSplitItem() + categoryId +
               super.getSplitItem() + visCode;
    }
}
